<?php

namespace app\admin\controller;

use app\admin\model\AdminUserModel;
use app\common\lib\Tool;
use think\Controller;
use think\Db;
use think\Session;

class Login extends Controller
{
    public function index()
    {
        return $this->fetch();
    }

    public function login()
    {
        $user = input('username');
        $password = input('password');
        $model = new AdminUserModel();
        if ($model->login($user, $password)) {
            $model = new Session();
            $model->set('username',$user);
            return Tool::json(1, [], '登录成功');
        } else {
            return Tool::json(0, [], $model->error);
        }
    }

    public function verifyPwd($id, $password)
    {
        if (!$id) {
            return false;
        }
        $info = $user = Db::name('member')
            ->field('password,status')
            ->where('id', $id)
            ->find();
        if ($info['password'] == pwd_encrypt($password)) {
            return true;
        }
        return false;
    }
}
